//
//  SISSNetworkingManager+Home.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/22.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSNetworkingManager+Home.h"

@implementation SISSNetworkingManager (Home)

// 2.1.1 首页20条最新房源客源
- (void)requestNewestHouseResourceWithSuccess:(void (^)(NSArray<SISSHouseResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
   
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"soId":[SISSUserAccount shared].soId,
                                 @"sobId":[SISSUserAccount shared].sobId,
                                 @"saId":[SISSUserAccount shared].saId
                                 };
    
    [kNetworkManager POSTWithURLString:URL_HOME_NEWEST_HOUSE parameters:parameters success:^(id responseObject) {
        NSLog(@"2.1.1 首页20条最新房源: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *houseResourceArr = [NSArray yy_modelArrayWithClass:[SISSHouseResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(houseResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.1.2 首页最新20条客源
- (void)requestNewestPassengerResourceWithSuccess:(void (^)(NSArray<SISSPassengerResourceModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
   
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"soId":[SISSUserAccount shared].soId,
                                 @"sobId":[SISSUserAccount shared].sobId,
                                 @"saId":[SISSUserAccount shared].saId
                                 };
    
    [kNetworkManager POSTWithURLString:URL_HOME_NEWEST_PASSENGER parameters:parameters success:^(id responseObject) {
        NSLog(@"2.1.2 首页最新20条客源: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *passengerResourceArr = [NSArray yy_modelArrayWithClass:[SISSPassengerResourceModel class] json:dataArr];
        if (successBlock) {
            successBlock(passengerResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.1.4 获取最新的租客
- (void)requestNewestTenantResourceWithSuccess:(void (^)(NSArray<SISSTenantModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"soId":[SISSUserAccount shared].soId,
                                 @"sobId":[SISSUserAccount shared].sobId,
                                 @"saId":[SISSUserAccount shared].saId};
    
    [kNetworkManager GETWithURLString:URL_HOME_NEWEST_TENANT parameters:parameters success:^(id responseObject) {
        NSLog(@"2.1.4 获取最新的租客: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *tenantResourceArr = [NSArray yy_modelArrayWithClass:[SISSTenantModel class] json:dataArr];
        if (successBlock) {
            successBlock(tenantResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.3.1 模糊搜索房源的请求 GET
- (void)requestFuzzySearchHouseWithKey:(NSString *)key success:(void (^)(NSArray<SISSFuzzySearchModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
   
    int type = 1;
    // 判断字符串key是中文还是英文
    NSString *subString = [key substringToIndex:1];
    const char *cString = [subString UTF8String];
    if (strlen(cString) == 1) {
        type = 1; // 英文
    } else if (strlen(cString) == 3) {
        type = 2; // 中文
    }
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"key":key,
                                 @"type":@(type)
                                 };
    
    [kNetworkManager GETWithURLString:URL_FUZZY_SEARCH_HOUSE parameters:parameters success:^(id responseObject) {
        NSLog(@"2.3.1 模糊搜索房源的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *fuzzySearchsArr = [NSArray yy_modelArrayWithClass:[SISSFuzzySearchModel class] json:dataArr];
        if (successBlock) {
            successBlock(fuzzySearchsArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }

    }];
}

// 2.3.2 模糊搜索客源 GET请求
- (void)requestFuzzySearchPassengerWithKey:(NSString *)key success:(void (^)(NSArray<SISSFuzzySearchModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
   
    int type = 1;
    // 判断字符串key是中文还是英文
    NSString *subString = [key substringToIndex:1];
    const char *cString = [subString UTF8String];
    if (strlen(cString) == 1) {
        type = 1; // 英文
    } else if (strlen(cString) == 3) {
        type = 2; // 中文
    }
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"key":key,
                                 @"type":@(type)};
    
    [kNetworkManager GETWithURLString:URL_FUZZY_SEARCH_PASSENGER parameters:parameters success:^(id responseObject) {
        NSLog(@"2.3.2 模糊搜索客源的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *fuzzySearchsArr = [NSArray yy_modelArrayWithClass:[SISSFuzzySearchModel class] json:dataArr];
        if (successBlock) {
            successBlock(fuzzySearchsArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
        
    }];
}

// 2.3.3 模糊搜索房源合作
- (void)requestFuzzySearchHouseCooperationWithKey:(NSString *)key success:(void (^)(NSArray<SISSFuzzySearchModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
   
    int type = 1;
    // 判断字符串key是中文还是英文
    NSString *subString = [key substringToIndex:1];
    const char *cString = [subString UTF8String];
    if (strlen(cString) == 1) {
        type = 1; // 英文
    } else if (strlen(cString) == 3) {
        type = 2; // 中文
    }
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"key":key,
                                 @"type":@(type)};
    
    [kNetworkManager GETWithURLString:URL_FUZZY_SEARCH_HOUSE_COOPERATION parameters:parameters success:^(id responseObject) {
        NSLog(@"2.3.3 模糊搜索房源合作的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *fuzzySearchsArr = [NSArray yy_modelArrayWithClass:[SISSFuzzySearchModel class] json:dataArr];
        if (successBlock) {
            successBlock(fuzzySearchsArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
        
    }];
}



// 模糊搜索客源合作
- (void)requestFuzzySearchPassengerCooperationWithKey:(NSString *)key success:(void (^)(NSArray<SISSFuzzySearchModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
   
    int type = 1;
    // 判断字符串key是中文还是英文
    NSString *subString = [key substringToIndex:1];
    const char *cString = [subString UTF8String];
    if (strlen(cString) == 1) {
        type = 1; // 英文
    } else if (strlen(cString) == 3) {
        type = 2; // 中文
    }
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"key":key,
                                 @"type":@(type)};
    
    [kNetworkManager GETWithURLString:URL_FUZZY_SEARCH_PASSENGER_COOPERATION parameters:parameters success:^(id responseObject) {
        NSLog(@"模糊搜索客源合作的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *fuzzySearchsArr = [NSArray yy_modelArrayWithClass:[SISSFuzzySearchModel class] json:dataArr];
        if (successBlock) {
            successBlock(fuzzySearchsArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
        
    }];
}

// 2.3.5 出租模糊搜索 GET请求
- (void)requestFuzzySearchRentOutWithKey:(NSString *)key success:(void (^)(NSArray<SISSFuzzySearchModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    int type = 1;
    // 判断字符串key是中文还是英文
    NSString *subString = [key substringToIndex:1];
    const char *cString = [subString UTF8String];
    if (strlen(cString) == 1) {
        type = 1; // 英文
    } else if (strlen(cString) == 3) {
        type = 2; // 中文
    }
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"key":key,
                                 @"type":@(type)};
    
    [kNetworkManager GETWithURLString:URL_FUZZY_SEARCH_RENTOUT parameters:parameters success:^(id responseObject) {
        NSLog(@"2.3.5 出租模糊搜索 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *fuzzySearchsArr = [NSArray yy_modelArrayWithClass:[SISSFuzzySearchModel class] json:dataArr];
        if (successBlock) {
            successBlock(fuzzySearchsArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
        
    }];
}

// 2.3.6 租客模糊搜索 GET请求
- (void)requestFuzzySearchTenantWithKey:(NSString *)key success:(void (^)(NSArray<SISSFuzzySearchModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    int type = 1;
    // 判断字符串key是中文还是英文
    NSString *subString = [key substringToIndex:1];
    const char *cString = [subString UTF8String];
    if (strlen(cString) == 1) {
        type = 1; // 英文
    } else if (strlen(cString) == 3) {
        type = 2; // 中文
    }
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"key":key,
                                 @"type":@(type)};
    
    [kNetworkManager GETWithURLString:URL_FUZZY_SEARCH_TENANT parameters:parameters success:^(id responseObject) {
        NSLog(@"2.3.6 租客模糊搜索 GET请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *fuzzySearchsArr = [NSArray yy_modelArrayWithClass:[SISSFuzzySearchModel class] json:dataArr];
        if (successBlock) {
            successBlock(fuzzySearchsArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.5.1 房源合作请求
- (void)requestHouseCooperationRequestWithparameters:(NSDictionary *)parameters success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {

    [SISSPublicSingleton shared].isHud = NO;//
    [kNetworkManager POSTWithURLString:URL_REQUEST_HOUSE_COOPERATION parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.5.1 房源合作请求的请求: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];

}

// 2.5.2 客源合作请求
- (void)requestPassengerCooperationRequestWithparameters:(NSDictionary *)parameters success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [SISSPublicSingleton shared].isHud = NO;//
    [kNetworkManager POSTWithURLString:URL_REQUEST_PASSENGER_COOPERATION parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.5.2 客源合作请求的请求: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.6.1 房源合作详情 GET请求
- (void)requestHouseCooperationDetailWithparameters:(NSDictionary *)parameters success:(void (^)(SISSHouseCooperationDetailModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kNetworkManager GETWithURLString:URL_HOUSE_COOPERATION_DETAIL parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.6.1 房源合作详情的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *cooperationDetailArr = [NSArray yy_modelArrayWithClass:[SISSHouseCooperationDetailModel class] json:dataArr];
        if (successBlock) {
            successBlock(cooperationDetailArr.firstObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.6.2 客源合作详情 GET请求
- (void)requestPassengerCooperationDetailWithparameters:(NSDictionary *)parameters success:(void (^)(SISSPassengerCooperationDetailModel *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kNetworkManager GETWithURLString:URL_PASSENGER_COOPERATION_DETAIL parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.6.2 客源合作详情的请求: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *cooperationDetailArr = [NSArray yy_modelArrayWithClass:[SISSPassengerCooperationDetailModel class] json:dataArr];
        
        if (successBlock) {
            successBlock(cooperationDetailArr.firstObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.7.1 插入房源已读记录
- (void)setHouseResourceReadWithHouseId:(NSString *)houseId success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
   
    NSDictionary *parameters = @{
                                 @"ahrId":houseId,
                                 @"saId":[SISSUserAccount shared].saId
                                 };
    
    [kNetworkManager POSTWithURLString:URL_HOUSE_RESOURCE_READ parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.7.1 插入房源已读记录的请求: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
    
}

// 2.7.2 插入客源已读记录
- (void)setPassengerResourceReadWithPassengerId:(NSString *)passengerId success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {

    NSDictionary *parameters = @{
                                 @"abdId":passengerId,
                                 @"saId":[SISSUserAccount shared].saId
                                 };
    
    [kNetworkManager POSTWithURLString:URL_PASSENGER_RESOURCE_READ parameters:parameters success:^(id responseObject) {
        
         NSLog(@"2.7.2 插入客源已读记录的请求: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}


// 2.8.1 举报
- (void)reportRecordWithparameters:(NSDictionary *)parameters success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    [kNetworkManager POSTWithURLString:URL_REPORT_RECORD parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.8.1 举报的请求: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }

    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.3.1 发布房源合作
- (void)releaseHouseCooperationWithparameters:(NSDictionary *)parameters success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    [SISSPublicSingleton shared].isHud = NO;//
    [kNetworkManager POSTWithURLString:URL_RELEASE_HOUSE_COOPERATION parameters:parameters success:^(id responseObject) {
        
        NSLog(@"3.3.1 发布房源合作的请求: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 3.3.2 发布客源合作
- (void)releasePassengerCooperationWithparameters:(NSDictionary *)parameters success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    [SISSPublicSingleton shared].isHud = NO;//
    [kNetworkManager POSTWithURLString:URL_RELEASE_PASSENGER_COOPERATION parameters:parameters success:^(id responseObject) {
        NSLog(@"3.3.2 发布客源合作的请求: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

#pragma mark - 2.0

// 2.1.3 获取最新的出租
- (void)requestNewestRentOutResourceWithSuccess:(void (^)(NSArray<SISSRentOutModel *> *))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"soId":[SISSUserAccount shared].soId,
                                 @"sobId":[SISSUserAccount shared].sobId,
                                 @"saId":[SISSUserAccount shared].saId};
    
    [kNetworkManager GETWithURLString:URL_HOME_NEWEST_RENTOUT parameters:parameters success:^(id responseObject) {
        NSLog(@"2.1.3 获取最新的出租: responseObject-->%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] != 200) {
            
            NSLog(@"%@",responseObject[@"data"]);
        }
        
        NSArray *dataArr = responseObject[@"data"];
        
        NSArray *rentOutResourceArr = [NSArray yy_modelArrayWithClass:[SISSRentOutModel class] json:dataArr];
        if (successBlock) {
            successBlock(rentOutResourceArr);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}


// 2.7.3 设置出租已读
- (void)setRentOutResourceReadWithRentOutId:(NSString *)rentOutId success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"alrId":rentOutId,
                                 @"saId":[SISSUserAccount shared].saId
                                 };
    
    [kNetworkManager POSTWithURLString:URL_RENTOUT_RESOURCE_READ parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.7.3 设置出租已读: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.7.4 设置租客已读
- (void)setTenantResourceReadWithTenantId:(NSString *)tenantId success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"arrId":tenantId,
                                 @"saId":[SISSUserAccount shared].saId
                                 };
    
    [kNetworkManager POSTWithURLString:URL_TENANT_RESOURCE_READ parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.7.4 设置租客已读: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.9.3 添加推荐租客记录
- (void)requestInsertRecommendTenantWithAlrId:(NSString *)alrId arrId:(NSString *)arrId arbpId:(NSString *)arbpId rentType:(NSInteger)rentType success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"alrId":alrId,
                                 @"arrId":arrId,
                                 @"arbpId":arbpId,
                                 @"rentType":@(rentType)
                                 };
    
//    [SISSPublicSingleton shared].isHud = NO;//
    [kNetworkManager POSTWithURLString:URL_RECOMMEND_TENANT parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.9.3 添加推荐租客记录: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}

// 2.9.4 添加推荐出租记录
- (void)requestInsertRecommendTRentOutWithArrId:(NSString *)arrId alrId:(NSString *)alrId albpId:(NSString *)albpId rentType:(NSInteger)leaseType success:(void (^)(id))successBlock failed:(void (^)(NSError *))failedBlock {
    
    NSDictionary *parameters = @{
                                 @"spId":[SISSUserAccount shared].spId,
                                 @"arrId":arrId,
                                 @"alrId":alrId,
                                 @"albpId":albpId,
                                 @"leaseType":@(leaseType)
                                 };
    
    [SISSPublicSingleton shared].isHud = NO;//
    [kNetworkManager POSTWithURLString:URL_RECOMMEND_RENTOUT parameters:parameters success:^(id responseObject) {
        
        NSLog(@"2.9.4 添加推荐出租记录: responseObject-->%@",responseObject);
        if (successBlock) {
            successBlock(responseObject);
        }
        
    } failure:^(NSError *error) {
        if (failedBlock) {
            failedBlock(error);
        }
    }];
}



@end
